<template>
  <div>
    <div class="whole-xloop">
      <div v-if="!(list.length == 0 && title == '' && finished)">
        <div class="title">我的奖励</div>
        <div class="my_rewards">
          <div class="rewards">
            <div class="rewards-title">免单次数</div>
            <div class="rewards-money"><span class="money-num">{{ rewards.issued_number}}</span></div>
          </div>
          <div class="rewards">
            <div class="rewards-title">免单金额</div>
            <div class="rewards-money"><span class="money-num" v-html="scaleGoodsPriceFn(rewards.issued_money)"></span></div>
          </div>
          <div class="rewards">
            <div class="rewards-title">赠送积分</div>
            <div class="rewards-money">{{ rewards.issued_point }}</div>
          </div>
        </div>
      </div>
      <div class="my_promotion" v-if="!(list.length == 0 && title == '' && finished)">
        <search :searchInfo="searchInfo" @search="searchFn" newStyle="2"></search>
      </div>
      <div class="activity-list">
        <van-list
          v-model="loading"
          :finished="finished"
          :error.sync="error"
          error-text="请求失败，点击重新加载"
          finished-text=""
          @load="onLoad"
        >
          <div class="list" v-for="item in list" :key="item.id">
            <div class="status" :class="item.activity_status == 1 ? '' : 'end_status'">{{item.activity_status_name}}</div>
            <div class="title list-title">{{item.name}}</div>
            <div class="time">活动结束时间：{{ item.end_time }}</div>
            <div class="order-get">
              <div class="order">
                <div class="order-title">我的订单数</div>
                <div class="order-num">{{item.count}}</div>
              </div>
              <div class="order">
                <div class="order-title">已返金额</div>
                <div class="order-num"><span class="money-num" v-html="scaleGoodsPriceFn(item.money)"></span></div>
              </div>
            </div>
            <div class="check-btn">
              <div class="check-order" @click="jumpName('freeQueuingDetails', {id: item.activity_id})">查看详情</div>
              <div class="shop-again" v-if="item.is_first_order === '0'" @click="jumpName('item-list', {link: 3, activity_id: item.activity_id})">再次参与</div>
            </div>
          </div>
        </van-list>
      
      </div>

    </div>
    <div v-if="list.length == 0 && finished">
      <no-data :noData="noData"></no-data>
      <div class="data-btn" v-if="title == ''">
        <div class="go-shopping" @click="jumpName('item-list', {link: 3})">去商场购物</div>
      </div>
    </div>
  </div>
</template>
<script>
import { scaleGoodsPrice } from '@/utils/index.js'
import Search from '@/components/Search/index'
import noData from '@/components/noData'
import { freeOrderRewardList } from '@/api/user/freeQueuing/freeQueuing.js'

export default {
  components: {
    Search,
    noData
  },
  data() {
    return {
      searchInfo: {
        placeholder: '请输入活动名称搜索'
      },
      noData: {
        width: '240px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/xloop/no-order-xloop-active.png',
        text: '暂无参加活动',
        txtMarginTop: '0px'
      },
      title: '',
      rewards: {
        issued_number: 0,
        issued_money: 0,
        issued_point: 0
      },
      list: [],
      p: 1,
      loading: false,
      error: false,
      finished: false
    }
  },
  created() {
    this.init()
  },
  mounted() {
    // 小程序触底加载更多
    window.addEventListener('reachbottom', () => {
      this.onLoad()
    })
  },
  methods: {
    init() {
      freeOrderRewardList({ p: this.p, keyword: this.title }).then(res => {
        this.finished = false
        this.loading = false
        if (res.status == 1) {
          if (res.data && res.data.list.length > 0) {
            if (this.p == 1) {
              this.rewards = res.data.info
              this.list = res.data.list
            } else {
              this.list.push(...res.data.list)
            }
            this.p++
          } else {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 加载更多
    onLoad() {
      // this.finished = false
      if (this.p > 1) {
        this.init()
      }
    },
    jumpName(name, data) {
      this.$JumpName(this, name, data)
    },
    scaleGoodsPriceFn(price) {
      return scaleGoodsPrice(price)
    },
    // 点击搜索
    searchFn(keyword) {
      this.p = 1
      this.title = keyword
      this.finished = false
      this.list = []
      this.init()
    }
  }
}
</script>
<style lang="scss">
  .rewards-money{
    .money-num {
      .price-scale {
        font-size: 24px;
        color: #fff;
        font-weight: 700;
        .num-font{
          font-size: 40px;
          color: #fff;
          font-weight: 700;
        }
      }
    }
  }
  .order-num {
    .money-num {
      .price-scale {
        font-size: 24px;
        color:#FD4149;
        font-weight: 700;
        .num-font{
          font-size: 40px;
          color: #FD4149;
          font-weight: 700;
        }
      }
    }
  }

  .whole-xloop {
    padding: 0 16px;
    .my_rewards {
      padding: 32px 0;
      background: linear-gradient(180deg, #FE754F 0%, #FD4149 100%);
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      text-align: center;
      position: relative;
      // min-height: 184px;
      font-size: 24px;
      .rewards {
        color: #fff;
        // margin: 16px 0;
        .rewards-title {
          margin-bottom: 14px;
        }
        .rewards-money {
          color: #fff;
          font-size: 40px;
          font-weight: 700;
        }
      }
    }
    .my_promotion {
      margin: 24px 0;
      .promotion {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 16px;
        .sub_title {
          font-size: 24px;
          img {
            width: 24px;
            height: 24px;
            position: relative;
            top: 2px;
            margin-left: 8px;
          }
        }
      }
    }
    .activity-list {
      .list {
        border-radius: 12px;
        background: #fff;
        padding: 24px;
        position: relative;
        margin-bottom: 16px;
        .status {
          color: #FD4149;
          font-size: 28px;
          position: absolute;
          right: 24px;
          top: 24px;
          &.end_status {
            color: #999
          }
        }
        .time {
          font-size: 24px;
          margin-top: 16px;
        }
        .order-get {
          display: flex;
          justify-content: space-around;
          align-items: center;
          padding: 40px;
          // border-bottom: 2px solid #F2F3F5;
          .order {
            text-align: center;
            .order-title {
              font-size: 24px;
              color: #999;
              margin-bottom: 16px;
            }
            .order-num {
              color: #FD4149;
              font-size: 40px;
              font-weight: 700;
            }
          }
        }
        .check-btn {
          display: flex;
          justify-content: space-around;
          align-items: center;
          font-size: 32px;
          text-align: center;
          div {
            padding: 16px 0;
            border: 1px solid #FD4149;
            width: 50%;
            border-radius: 8px;
          }
          .check-order {
            color: #FD4149;
            margin-right: 26px;
          }
          .shop-again {
            background: #FD4149;
            color: #fff;
            
          }
        }
      }
    }
    .title {
      color: #333;
      font-size: 28px;
      font-weight: 500;
      padding: 16px 0;
      margin-left: 8px;
      line-height: 140%;
      &.list-title {
        width: 80%;
        padding: 0;
        margin-left: 0px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;

      }
    }
  }
  .data-btn {
    display: flex;
    align-items: center;
    justify-content:space-around;
    margin: 0 40px;
    .check-superior {
      border-radius: 200px;
      border: 2px solid #FD4149;
      color: #FD4149;
      font-size: 28px;
      width: 290px;
      height: 72px;
      line-height: 72px;
      text-align: center;
    }
    .go-shopping {
      border-radius: 200px;
      background: linear-gradient(90deg, #FE754F -0.78%, #FD4149 99.06%), linear-gradient(92deg, #00ADBD 1.71%, #04C1AB 98.29%);
      color: #fff;
      font-size: 28px;
      width: 290px;
      height: 72px;
      line-height: 72px;
      text-align: center;
    }
  }
  .no-data {
    padding: 72px 0!important;
  }

</style>